import logging
# logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# logging.basicConfig(filename='project.log', level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# logging.debug('This is a debug message')
# logging.info('This is an info message')
# logging.warning('This is a warning message')
# logging.error('This is an error message')
# logging.critical('This is a critical message')

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
sh = logging.StreamHandler() # 输出到控制台
sh.setLevel(logging.DEBUG) # 设置级别，低于该级别的日志不会输出到控制台
sh.setFormatter(formatter)
fh = logging.FileHandler('project.log') # 输出到文件
fh.setLevel(logging.WARNING) # 设置级别，低于该级别的日志不会输出到文件
fh.setFormatter(formatter)
logger.addHandler(sh)
logger.addHandler(fh)


logging.debug('This is a debug message')
logging.info('This is an info message')
logging.warning('This is a warning message')
logging.error('This is an error message')
logging.critical('This is a critical message')